package com.ymatou.iapi.trading.sellerquery2.testcase;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.operate.parameter.PlaceOrderResp;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderService;
import com.ymatou.iapi.trading.ordersync.service.SyncVerifyService;
import com.ymatou.iapi.trading.sellerquery2.parameter.GetCustomServiceOrderListBean;
import com.ymatou.iapi.trading.sellerquery2.parameter.resp.GetCustomServiceOrder;
import com.ymatou.iapi.trading.sellerquery2.parameter.resp.GetCustomServiceOrderListResp;
import com.ymatou.iapi.trading.sellerquery2.service.GetCustomServiceOrderListCall;
import com.ymatou.operate.trading.api.parameter.DispatchedBean;
import com.ymatou.operate.trading.api.service.DispatchedCall;
import com.ymatou.query.seller.trading.api.parameter.Pagination;
import com.ymatou.query.seller.trading.api.service.OrderCreate;
import com.ymt.base.YmatouEasyCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.common.enums.BillTypeEnum;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.YMTDateUtil;

/**
 * 订单查询请求(客服团队)
 * 
 * @date 2016-09-14
 */
@TestSuite
public class Ts_GetCustomServiceOrderList {

	private static GetCustomServiceOrderListBean getCustomServiceOrderListBean;
	private static GetCustomServiceOrderListCall getCustomServiceOrderListCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("订单查询请求(客服团队)");
	}

	@Before
	public void caseUp() {
		getCustomServiceOrderListBean = new GetCustomServiceOrderListBean();

		getCustomServiceOrderListCall = new GetCustomServiceOrderListCall();
	}
	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getCustomServiceOrderListCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	/**
	 * 码头保存发货物流单号
	 * 
	 * @param orderId
	 * @param sellerId
	 * */
	private String saveDeliverSummary(Integer orderId, int sellerId) {
		String billCode_sit1 = "DB683214922US";
		String billCode_uat = "DB753209166US";
		String billCode = EnvSetup.getEnv().equals("sit1")
				? billCode_sit1
				: billCode_uat;
		try {
			YmatouEasyCall SaveDeliverSummaryCall = new YmatouEasyCall("",
					"POST", "JSON");
			StringBuffer saveDeliverSummaryString = new StringBuffer();
			saveDeliverSummaryString
					.append("{\"SaveDeliverSummaryInfos\":[{\"BillCode\":\"");
			saveDeliverSummaryString.append(billCode);
			saveDeliverSummaryString.append("\",");
			saveDeliverSummaryString
					.append("\"CanReDelivery\":0,\"DeliverType\":2,\"ExpressCode\":\"xlobo\",\"InnerExpressCode\":\"\",\"IsChinaDeliver\":false,");
			saveDeliverSummaryString.append("\"OrderId\":");
			saveDeliverSummaryString.append(orderId);
			saveDeliverSummaryString.append(",");
			saveDeliverSummaryString
					.append("\"Provider\":\"洋码头官方合作物流（xLobo贝海国际速递）\",");
			saveDeliverSummaryString.append("\"SellerId\":");
			saveDeliverSummaryString.append(sellerId);
			saveDeliverSummaryString.append(",");
			saveDeliverSummaryString.append("\"Weight\":10}]}");
			SaveDeliverSummaryCall
					.setUrl("http://api.seller.ymatou.com/api/Deliver/SaveDeliverSummary");

			SaveDeliverSummaryCall.setData(saveDeliverSummaryString.toString());
			Logger.comment("发货处理");
			SaveDeliverSummaryCall.callService();

			if (new JSONObject(SaveDeliverSummaryCall.getReturnData())
					.getInt("Code") == 200)
				return billCode;

		} catch (Exception e) {
			// TODO: handle exception
		}

		return null;

	}

	/**
	 * 非贝海发货
	 * 
	 * @param orderId
	 * @param sellerId
	 */
	private String dispatched(Integer orderId, int sellerId) {
		String DeliverSummary = saveDeliverSummary(orderId, sellerId);
		try {
			DispatchedBean dispatchedbean = new DispatchedBean();
			DispatchedCall dispatchedcall = new DispatchedCall();
			dispatchedbean.setBillType(BillTypeEnum.YMTAPI);
			// 物流单号
			dispatchedbean.setDeliverSummary(DeliverSummary);
			// Logger.debug(DeliverSummary);
			dispatchedbean.setDeliverType("0");
			dispatchedbean.setOrderId(orderId);
			dispatchedbean.setProvider("贝海");
			dispatchedbean.setSellerUserId(sellerId);

			BigDecimal Weight = new BigDecimal(10);
			dispatchedbean.setWeight(Weight);// 重量
			dispatchedbean.setIsShippedByXlobo(true);
			dispatchedcall.setData(false, dispatchedbean);
			Logger.comment("订单:" + orderId + "卖家:" + sellerId + "发货");
			dispatchedcall.callService();
			Logger.debug("发货send：" + dispatchedcall.getEntityString());
			Logger.debug("发货response：" + dispatchedcall.getReturnData());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return DeliverSummary;
	}

	// 根据总记录数，每页数 计算总共有多少页
	private int getTotalPage(int totalRecords, int pageSize) {
		int totalPage;
		if (totalRecords % pageSize > 0) {
			totalPage = (totalRecords / pageSize) + 1;
		} else {
			totalPage = (totalRecords / pageSize);
		}
		return totalPage;
	}

	private void verify() {

		GetCustomServiceOrderListResp expect = new GetCustomServiceOrderListResp();

		ConstructExpectedResponse(expect);

		GetCustomServiceOrderListResp actual = getCustomServiceOrderListCall
				.getCustomServiceOrderListResponse();

		if (expect.getOrderList().size() < 1) {
			DataUtil.verify(null, actual.getOrderList(), "验证期望的orderList为null");
		} else {
			boolean goon = actual.getOrderList().size() > 0;

			DataUtil.verify(true, goon, "验证期望的Order ！= null");
			if (goon) {

				verifyOrderList(expect.getOrderList(), actual.getOrderList());

			}
		}
	}
	private void verifyOrderList(List<GetCustomServiceOrder> expect,
			List<GetCustomServiceOrder> actual) {

		if (expect.size() != actual.size()) {
			DataUtil.verify(expect.size(), actual.size(), "验证返回oderList 条数");
			return;
		}

		for (int i = 0; i < expect.size(); i++) {

			GetCustomServiceOrder expectCustomServiceOrder = expect.get(i);
			GetCustomServiceOrder actualCustomServiceOrder = actual.get(i);

			DataUtil.verify(expectCustomServiceOrder.getOrderId(),
					actualCustomServiceOrder.getOrderId(), "验证OrderId=["
							+ actualCustomServiceOrder.getOrderId()
							+ "]的orderId");
			DataUtil.verify(expectCustomServiceOrder.getUserLogin(),
					actualCustomServiceOrder.getUserLogin(), "验证OrderId=["
							+ actualCustomServiceOrder.getOrderId()
							+ "]的userLogin");

			DataUtil.verify(expectCustomServiceOrder.getSellerLogin(),
					actualCustomServiceOrder.getSellerLogin(), "验证OrderId=["
							+ actualCustomServiceOrder.getOrderId()
							+ "]的sellerLogin");

			DataUtil.verify(expectCustomServiceOrder.getTradingStatus(),
					actualCustomServiceOrder.getTradingStatus(), "验证OrderId=["
							+ actualCustomServiceOrder.getOrderId()
							+ "]的tradingStatus");
			DataUtil.verifyDecimalEquals(expectCustomServiceOrder.getPrice(),
					actualCustomServiceOrder.getPrice(), "验证OrderId=["
							+ actualCustomServiceOrder.getOrderId() + "]的price");

			DataUtil.verifyDateEquals(expectCustomServiceOrder.getAddTime(),
					actualCustomServiceOrder.getAddTime(), "验证OrderId=["
							+ actualCustomServiceOrder.getOrderId()
							+ "]的addTime");

			DataUtil.verifyDateEquals(expectCustomServiceOrder.getPaidTime(),
					actualCustomServiceOrder.getPaidTime(), "验证OrderId=["
							+ actualCustomServiceOrder.getOrderId()
							+ "]的paidTime");

			DataUtil.verifyDateEquals(
					expectCustomServiceOrder.getDeliveryTime(),
					actualCustomServiceOrder.getDeliveryTime(), "验证OrderId=["
							+ actualCustomServiceOrder.getOrderId()
							+ "]的deliveryTime");

			DataUtil.verifyDateEquals(
					expectCustomServiceOrder.getReceiveTime(),
					actualCustomServiceOrder.getReceiveTime(), "验证OrderId=["
							+ actualCustomServiceOrder.getOrderId()
							+ "]的receiveTime");

			DataUtil.verify(expectCustomServiceOrder.getProducts(),
					actualCustomServiceOrder.getProducts(), "验证OrderId=["
							+ actualCustomServiceOrder.getOrderId()
							+ "]的products");

		}

	}

	private void ConstructExpectedResponse(
			GetCustomServiceOrderListResp response) {
		Process(response);
	}

	private void Process(GetCustomServiceOrderListResp response) {

		Pagination page = new Pagination(
				getCustomServiceOrderListBean.getPageNum(),
				getCustomServiceOrderListBean.getPageSize());

		StringBuilder sb = new StringBuilder();

		sb.append("select top 60 iOrderId as orderId, sBuyerLoginId as userLogin, sSellerLoginId as sellerLogin, iTradingStatus as tradingStatus,(fTotalPrice+fFreight+fOrderDiscount+fDiscount-fYmtCouponAmount-fSellerCouponAmount-fSellerPromotionAmount)as price,dAddTime as addTime,dPaidTime as paidTime,dDispathTime as deliveryTime,dConfirmedTime as receiveTime from ymt_orders where ");

		if (getCustomServiceOrderListBean.getOrderId() != null) {
			sb.append("iOrderId=" + getCustomServiceOrderListBean.getOrderId());
		}

		if (getCustomServiceOrderListBean.getSellerId() != null) {
			sb.append("and iBuyerId="
					+ getCustomServiceOrderListBean.getSellerId());
		}

		if (null != getCustomServiceOrderListBean.getDlvCode()) {
			sb.append("and iOrderId in(select OrderId from Ymt_BillCodeSummaryToOrders where billCodeSummaryID in(select BillCodeSummaryID from Ymt_BillCodeSummary where billCode ='"
					+ getCustomServiceOrderListBean.getDlvCode()
					+ "' and IsDeleted=0))");
		}
		if (null != getCustomServiceOrderListBean.getPhone()) {
			sb.append(" and sPhone='"
					+ getCustomServiceOrderListBean.getPhone() + "'");
		}
		if (null != getCustomServiceOrderListBean.getReceiver()) {
			sb.append(" and sReceivePerson='"
					+ getCustomServiceOrderListBean.getReceiver() + "'");
		}

		if (null != getCustomServiceOrderListBean.getMainOrderId()) {
			sb.append(" and iMainOrderId="
					+ getCustomServiceOrderListBean.getMainOrderId());
		}

		if (null != getCustomServiceOrderListBean.getBeginTime()) {
			sb.append(" and dAddTime >='"
					+ getCustomServiceOrderListBean.getBeginTime() + "'");
		}

		if (null != getCustomServiceOrderListBean.getEndTime()) {
			sb.append(" and dAddTime <='"
					+ getCustomServiceOrderListBean.getEndTime() + "'");

			sb.replace(0, 13, "select ");
		}

		if (getCustomServiceOrderListBean.getOrderId() == null
				&& getCustomServiceOrderListBean.getMainOrderId() == null) {

			if (null == getCustomServiceOrderListBean.getBeginTime()
					&& null == getCustomServiceOrderListBean.getEndTime()) {

				sb.append("and dAddTime >= dateadd(day,-90,getdate()) and dAddTime <= getdate()");

				sb.replace(0, 13, "select ");
			}
		}

		sb.append(" order by dAddTime DESC");

		//sql server 分页实现

		/*		sb.append(" offset @skip rows fetch next @limit rows only");
				sb.append(" select orderId,  userLogin, sellerLogin, tradingStatus,price,addTime, paidTime from @orders");
		*/

		DefaultWapper db = new DefaultWapper();

		String sql = sb.toString();
		if (sql.contains("where and")) {
			sql = sql.replace("where and", "where ");
		}

		List<Map> list = db.executeSql(sql);

		if (!DataUtil.isNullOrEmpty(list)) {

			List<GetCustomServiceOrder> orders = new ArrayList<GetCustomServiceOrder>();

			int pageIndex = getCustomServiceOrderListBean.getPageNum();

			int pageSize = getCustomServiceOrderListBean.getPageSize();

			// 最后一页
			if (pageIndex == getTotalPage(list.size(), pageSize)) {
				list = list.subList((pageIndex - 1) * pageSize, list.size());
			} else {
				list = list.subList((pageIndex - 1) * pageSize, pageIndex
						* pageSize);
			}

			for (Map m : list) {
				GetCustomServiceOrder order = new GetCustomServiceOrder();

				DataUtil.mapToBean(order, m);

				getOrderProducts(order);

				orders.add(order);
			}

			response.setOrderList(orders);
			response.setTotal(orders.size());
			response.setSuccess("true");

			Logger.debug("sql:" + sql);
		}
	}
	private void getOrderProducts(GetCustomServiceOrder getCustomServiceOrder) {

		int orderId = getCustomServiceOrder.getOrderId();
		DefaultWapper db = new DefaultWapper();

		List<Map> list = db
				.executeSql("select sProductId,sTitle from Ymt_OrderInfo  where iOrderId="
						+ orderId);

		if (!DataUtil.isNullOrEmpty(list)) {

			Map<String, String> products = new HashMap<String, String>();

			for (Map map : list) {

				products.put((String) map.get("sProductId"),
						(String) map.get("sTitle"));
			}

			getCustomServiceOrder.setProducts(products);

		}

	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetCustomServiceOrderList_000() {
		Logger.start(true, "客服后台根据orderId获取订单详情成功");

		String res;
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
				YMTDateUtil.YMDHMSS);

		long lt = new Long("1513586997455");
		Date date = new Date(lt);
		res = simpleDateFormat.format(date);

		Logger.info("res:" + res);

	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetCustomServiceOrderList_001() {
		Logger.start(true, "客服后台根据orderId获取订单详情成功");
		try {
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));

			Logger.comment("准备订单数据");

			OrderCreate o = new OrderCreate();

			int orderId = o.create4_ReceivedOrder(userId, sellerId)
					.getiOrderId();

			SyncVerifyService.getSyncResult(orderId);

			Logger.comment("完成准备订单数据");

			getCustomServiceOrderListBean.setSellerId(sellerId);

			getCustomServiceOrderListBean.setPageNum(1);

			getCustomServiceOrderListBean.setPageSize(1);

			getCustomServiceOrderListBean.setOrderId(orderId);

			getCustomServiceOrderListCall
					.setData(getCustomServiceOrderListBean);

			getCustomServiceOrderListCall.callService();

			Logger.verifyEquals("200", getCustomServiceOrderListCall.getCode(),
					"验证code");

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetCustomServiceOrderList_002() {
		Logger.start(true, "一个订单下有多个商品,客服后台根据orderId获取订单详情成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrder = PlaceOrderService.placeOrder4();

			int userId = placeOrder.getUserId();
			int sellerId = placeOrder.getOrderList().get(0).getSellerId();

			int tradingId = placeOrder.getTradingId();
			Integer orderId = placeOrder.getOrderList().get(0).getOrderId();

			BigDecimal price = placeOrder.getPayAmount();

			new OrderCallService().orderPayRequest(userId, price, tradingId);

			new OrderCallService().acceptOrder(orderId, sellerId);

			new OrderCallService().dispatched(orderId, sellerId);

			new OrderCallService().confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			SyncVerifyService.getSyncResult(orderId);

			getCustomServiceOrderListBean.setSellerId(sellerId);

			getCustomServiceOrderListBean.setPageNum(1);

			getCustomServiceOrderListBean.setPageSize(1);

			getCustomServiceOrderListBean.setOrderId(orderId);

			getCustomServiceOrderListCall
					.setData(getCustomServiceOrderListBean);

			getCustomServiceOrderListCall.callService();

			Logger.verifyEquals("200", getCustomServiceOrderListCall.getCode(),
					"验证code");

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetCustomServiceOrderList_003() {
		Logger.start(true, "根据物流单号查询,客服后台获取订单详情成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrder = PlaceOrderService.placeOrder4();

			int userId = placeOrder.getUserId();
			int sellerId = placeOrder.getOrderList().get(0).getSellerId();

			int tradingId = placeOrder.getTradingId();
			Integer orderId = placeOrder.getOrderList().get(0).getOrderId();

			BigDecimal price = placeOrder.getPayAmount();

			new OrderCallService().orderPayRequest(userId, price, tradingId);

			new OrderCallService().acceptOrder(orderId, sellerId);

			String dlvCode = this.dispatched(orderId, sellerId);

			new OrderCallService().confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			SyncVerifyService.getSyncResult(orderId);

			getCustomServiceOrderListBean.setSellerId(sellerId);

			getCustomServiceOrderListBean.setPageNum(1);

			getCustomServiceOrderListBean.setDlvCode(dlvCode);

			getCustomServiceOrderListBean.setPageSize(10);

			//getCustomServiceOrderListBean.setOrderId(orderId);

			getCustomServiceOrderListCall
					.setData(getCustomServiceOrderListBean);

			getCustomServiceOrderListCall.callService();

			Logger.verifyEquals("200", getCustomServiceOrderListCall.getCode(),
					"验证code");

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetCustomServiceOrderList_004() {
		Logger.start(true, "不传订单号，主订单号，默认查询90天订单数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrder = PlaceOrderService.placeOrder4();

			int userId = placeOrder.getUserId();
			int sellerId = placeOrder.getOrderList().get(0).getSellerId();

			/*			int tradingId = placeOrder.getTradingId();
						Integer orderId = placeOrder.getOrderList().get(0).getOrderId();

						BigDecimal price = placeOrder.getPayAmount();

						new OrderCallService().orderPayRequest(userId, price, tradingId);

						new OrderCallService().acceptOrder(orderId, sellerId);

						String dlvCode = this.dispatched(orderId, sellerId);

						new OrderCallService().confirmReceive(userId, orderId);*/

			Logger.comment("前置数据准备结束");

			//SyncVerifyService.getSyncResult(orderId);

			getCustomServiceOrderListBean.setSellerId(sellerId);

			getCustomServiceOrderListBean.setPageNum(1);

			//getCustomServiceOrderListBean.setDlvCode(dlvCode);

			getCustomServiceOrderListBean.setPageSize(25);

			//getCustomServiceOrderListBean.setOrderId(orderId);

			getCustomServiceOrderListCall
					.setData(getCustomServiceOrderListBean);

			getCustomServiceOrderListCall.callService();

			Logger.verifyEquals("200", getCustomServiceOrderListCall.getCode(),
					"验证code");

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetCustomServiceOrderList_005() {
		Logger.start(true, "只传订单创建开始截止时间，查询订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrder = PlaceOrderService.placeOrder4();

			int userId = placeOrder.getUserId();

			int sellerId = placeOrder.getOrderList().get(0).getSellerId();

			Integer orderId = placeOrder.getOrderList().get(0).getOrderId();

			Logger.comment("前置数据准备结束");

			Thread.sleep(3000);

			SyncVerifyService.getSyncResult(orderId);

			getCustomServiceOrderListBean.setSellerId(sellerId);

			getCustomServiceOrderListBean.setPageNum(1);

			getCustomServiceOrderListBean.setPageSize(25);

			getCustomServiceOrderListBean.setBeginTime(YMTDateUtil
					.getBeforeOrNextMonth(-1, "yyyy-MM-dd'T'HH:mm:ss"));

			getCustomServiceOrderListBean.setEndTime(YMTDateUtil
					.getBeforeOrNextMonth(0, "yyyy-MM-dd'T'HH:mm:ss"));

			getCustomServiceOrderListCall
					.setData(getCustomServiceOrderListBean);

			getCustomServiceOrderListCall.callService();

			Logger.verifyEquals("200", getCustomServiceOrderListCall.getCode(),
					"验证code");

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetCustomServiceOrderList_006() {
		Logger.start(true, "根据收件人手机号查询，查询订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrder = PlaceOrderService.placeOrder4();

			int userId = placeOrder.getUserId();

			int sellerId = placeOrder.getOrderList().get(0).getSellerId();

			Integer orderId = placeOrder.getOrderList().get(0).getOrderId();

			Logger.comment("前置数据准备结束");

			Thread.sleep(3000);

			SyncVerifyService.getSyncResult(orderId);

			getCustomServiceOrderListBean.setSellerId(sellerId);

			getCustomServiceOrderListBean.setPageNum(1);

			getCustomServiceOrderListBean.setPageSize(25);

			getCustomServiceOrderListBean.setPhone("13100000001");

			getCustomServiceOrderListBean.setBeginTime(YMTDateUtil
					.getBeforeOrNextMonth(-1, "yyyy-MM-dd'T'HH:mm:ss"));

			getCustomServiceOrderListBean.setEndTime(YMTDateUtil
					.getBeforeOrNextMonth(0, "yyyy-MM-dd'T'HH:mm:ss"));

			getCustomServiceOrderListCall
					.setData(getCustomServiceOrderListBean);

			getCustomServiceOrderListCall.callService();

			Logger.verifyEquals("200", getCustomServiceOrderListCall.getCode(),
					"验证code");

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetCustomServiceOrderList_007() {
		Logger.start(true, "根据收件人查询，查询订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrder = PlaceOrderService.placeOrder4();

			int userId = placeOrder.getUserId();

			int sellerId = placeOrder.getOrderList().get(0).getSellerId();

			Integer orderId = placeOrder.getOrderList().get(0).getOrderId();

			Logger.comment("前置数据准备结束");

			Thread.sleep(3000);

			SyncVerifyService.getSyncResult(orderId);

			getCustomServiceOrderListBean.setSellerId(sellerId);

			getCustomServiceOrderListBean.setPageNum(1);

			getCustomServiceOrderListBean.setPageSize(25);

			getCustomServiceOrderListBean.setReceiver("李四");

			getCustomServiceOrderListBean.setBeginTime(YMTDateUtil
					.getBeforeOrNextMonth(-1, "yyyy-MM-dd'T'HH:mm:ss"));

			getCustomServiceOrderListBean.setEndTime(YMTDateUtil
					.getBeforeOrNextMonth(0, "yyyy-MM-dd'T'HH:mm:ss"));

			getCustomServiceOrderListCall
					.setData(getCustomServiceOrderListBean);

			getCustomServiceOrderListCall.callService();

			Logger.verifyEquals("200", getCustomServiceOrderListCall.getCode(),
					"验证code");

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetCustomServiceOrderList_008() {
		Logger.start(true, "根据主订单号查询，查询订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrder = PlaceOrderService.placeOrder4();

			int userId = placeOrder.getUserId();

			int sellerId = placeOrder.getOrderList().get(0).getSellerId();

			Integer orderId = placeOrder.getOrderList().get(0).getOrderId();

			Integer mainOrderId = placeOrder.getTradingId();

			Logger.comment("前置数据准备结束");

			Thread.sleep(3000);

			SyncVerifyService.getSyncResult(orderId);

			getCustomServiceOrderListBean.setSellerId(sellerId);

			getCustomServiceOrderListBean.setPageNum(1);

			getCustomServiceOrderListBean.setMainOrderId(mainOrderId);

			getCustomServiceOrderListBean.setPageSize(25);

			getCustomServiceOrderListBean.setBeginTime(YMTDateUtil
					.getBeforeOrNextMonth(-1, "yyyy-MM-dd'T'HH:mm:ss"));

			getCustomServiceOrderListBean.setEndTime(YMTDateUtil
					.getBeforeOrNextMonth(0, "yyyy-MM-dd'T'HH:mm:ss"));

			getCustomServiceOrderListCall
					.setData(getCustomServiceOrderListBean);

			getCustomServiceOrderListCall.callService();

			Logger.verifyEquals("200", getCustomServiceOrderListCall.getCode(),
					"验证code");

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetCustomServiceOrderList_009() {
		Logger.start(true, "不传订单号，主订单号，查询第二页数据");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrder = PlaceOrderService.placeOrder4();

			int userId = placeOrder.getUserId();
			int sellerId = placeOrder.getOrderList().get(0).getSellerId();

			/*			int tradingId = placeOrder.getTradingId();
						Integer orderId = placeOrder.getOrderList().get(0).getOrderId();

						BigDecimal price = placeOrder.getPayAmount();

						new OrderCallService().orderPayRequest(userId, price, tradingId);

						new OrderCallService().acceptOrder(orderId, sellerId);

						String dlvCode = this.dispatched(orderId, sellerId);

						new OrderCallService().confirmReceive(userId, orderId);*/

			Logger.comment("前置数据准备结束");

			//SyncVerifyService.getSyncResult(orderId);

			getCustomServiceOrderListBean.setSellerId(sellerId);

			getCustomServiceOrderListBean.setPageNum(2);

			//getCustomServiceOrderListBean.setDlvCode(dlvCode);

			getCustomServiceOrderListBean.setPageSize(25);

			//getCustomServiceOrderListBean.setOrderId(orderId);

			getCustomServiceOrderListCall
					.setData(getCustomServiceOrderListBean);

			getCustomServiceOrderListCall.callService();

			Logger.verifyEquals("200", getCustomServiceOrderListCall.getCode(),
					"验证code");

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetCustomServiceOrderList_010() {
		Logger.start(true, "当前页面为空,获取订单详情成功");
		try {
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));

			getCustomServiceOrderListBean.setSellerId(sellerId);

			//getCustomServiceOrderListBean.setPageNum(1);

			getCustomServiceOrderListBean.setPageSize(1);

			getCustomServiceOrderListBean.setOrderId(111111);

			getCustomServiceOrderListCall
					.setData(getCustomServiceOrderListBean);

			getCustomServiceOrderListCall.callService();

			Logger.verifyEquals("400", getCustomServiceOrderListCall.getCode(),
					"验证code");
			Logger.verifyEquals("100",
					getCustomServiceOrderListCall.getBCode(), "验证bcode");

			Logger.verifyEquals("pageNum:页号最小为1",
					getCustomServiceOrderListCall.getMsg(), "验证msg");
			//verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetCustomServiceOrderList_011() {
		Logger.start(true, "当前页面为空,获取订单详情成功");
		try {
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));

			getCustomServiceOrderListBean.setSellerId(sellerId);

			getCustomServiceOrderListBean.setPageNum(1);

			//getCustomServiceOrderListBean.setPageSize(1);

			getCustomServiceOrderListBean.setOrderId(111111);

			getCustomServiceOrderListCall
					.setData(getCustomServiceOrderListBean);

			getCustomServiceOrderListCall.callService();

			Logger.verifyEquals("400", getCustomServiceOrderListCall.getCode(),
					"验证code");
			Logger.verifyEquals("100",
					getCustomServiceOrderListCall.getBCode(), "验证bcode");

			Logger.verifyEquals("pageSize:每页数量最小为1",
					getCustomServiceOrderListCall.getMsg(), "验证msg");
			//verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetCustomServiceOrderList_012() {
		Logger.start(true, "当前页面为空,获取订单详情成功");
		try {
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));

			getCustomServiceOrderListBean.setSellerId(sellerId);

			getCustomServiceOrderListBean.setPageNum(1);

			getCustomServiceOrderListBean.setPageSize(25);

			getCustomServiceOrderListBean.setSellerId(sellerId);

			getCustomServiceOrderListCall
					.setData(getCustomServiceOrderListBean);

			getCustomServiceOrderListCall.callService();

			Logger.verifyEquals("200", getCustomServiceOrderListCall.getCode(),
					"验证code");

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetCustomServiceOrderList_013() {
		Logger.start(true, "客服后台根据商品标题,获取订单详情成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrder = PlaceOrderService.placeOrder4();

			int sellerId = placeOrder.getOrderList().get(0).getSellerId();

			Integer orderId = placeOrder.getOrderList().get(0).getOrderId();

			Logger.comment("前置数据准备结束");

			Thread.sleep(3000);

			SyncVerifyService.getSyncResult(orderId);

			getCustomServiceOrderListBean.setSellerId(sellerId);

			getCustomServiceOrderListBean.setPageNum(1);

			getCustomServiceOrderListBean.setPageSize(25);

			getCustomServiceOrderListBean.setReceiver("钱翼");

			getCustomServiceOrderListBean.setTitle("测试");

			getCustomServiceOrderListBean.setTradingStatus(12);

			getCustomServiceOrderListBean.setDeliveryType(7);

			getCustomServiceOrderListBean.setBeginTime(YMTDateUtil
					.getBeforeOrNextMonth(-1, "yyyy-MM-dd'T'HH:mm:ss"));

			getCustomServiceOrderListBean.setEndTime(YMTDateUtil
					.getBeforeOrNextMonth(0, "yyyy-MM-dd'T'HH:mm:ss"));

			getCustomServiceOrderListCall
					.setData(getCustomServiceOrderListBean);

			getCustomServiceOrderListCall.callService();

			Logger.verifyEquals("200", getCustomServiceOrderListCall.getCode(),
					"验证code");

			verify();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
